<?php

namespace App\Admin\Controllers;

use App\Models\Config;
use Encore\Admin\Form;
use Encore\Admin\Controllers\AdminController;

class ConfigsController extends AdminController
{
    protected $title = '全局配置';

    protected function form()
    {
        $form = new Form(new Config());

        $form->tab('基本配置', function ($form) {
	        $form->text('system_name', '系统名称')->default('System Name');
	        $form->image('logo', 'LOGO')->uniqueName();
	        $form->text('copyright', '版权说明');
	        $form->text('icp_bei', 'ICP备');
	        $form->text('icp_zheng', 'ICP证');
	        $form->text('gongan_bei', '公安备');
	        $form->mobile('phone', '公司手机')->rules('nullable|phone:CN,mobile');
	        $form->text('address', '公司地址');
	        $form->image('serve_qrcode', '排行榜banner图')->uniqueName();
			$form->image('produce_image', '排行榜长图')->uniqueName();
	        
        })->tab('支付方式', function ($form) {
            $form->select('alipay_route', '支付宝路由')
                ->options([
                    'YJEG0' => '一加二购(主)',
                    'YJEG1' => '一加二购(子2023)',
                    'YJEG2' => '一加二购(子2024)',
                    'YJEG3' => '一加二购(子2025)',
                    'YJEG4' => '一加二购(子2026)',
                    'QLWL0' => '晴朗网络(主)',
                ]);
            $form->select('adapay_route', '汇付天路由')
                ->options([
                    'YJEG0' => '一加二购(主)',
                    'YJEG1' => '一加二购(子2023)',
                    'YJEG2' => '一加二购(子2024)',
                    'YJEG3' => '一加二购(子2025)',
                    'YJEG4' => '一加二购(子2026)',
                ]);
        })->tab('关于我们', function ($form) {
        	$url = config('app.url').'/wap/configs/about/us';
        	$form->html("<h4>URL: {$url}</h4>");
	        $form->simditor('about_us', '关于我们');
        })->tab('用户协议', function ($form) {
	        $url = config('app.url').'/wap/configs/user/agreement';
	        $form->html("<h4>URL: {$url}</h4>");
	        $form->simditor('user_agreement', '用户协议');
        })->tab('隐私协议', function ($form) {
	        $url = config('app.url').'/wap/configs/user/privacy';
	        $form->html("<h4>URL: {$url}</h4>");
	        $form->simditor('privacy_agreement', '隐私协议');
        })->tab('会员协议', function ($form) {
	        $url = config('app.url').'/wap/configs/user/service';
	        $form->html("<h4>URL: {$url}</h4>");
	        $form->simditor('service_agreement', '会员协议');
        })->tab('应用攻略', function ($form) {
	        $url = config('app.url').'/wap/configs/user/usage';
	        $form->html("<h4>URL: {$url}</h4>");
	        $form->simditor('user_usage', '应用攻略');
        });

        $this->formTools($form);
        $this->formSaved($form);
        $this->formFooter($form);

        return $form;
    }

    protected function formTools(Form $form)
    {
    	$form->tools(function (Form\Tools $tools) {
    		$tools->disableList();
    		$tools->disableView();
    		$tools->disableDelete();
	    });
    }

    protected function formFooter(Form $form)
    {
    	$form->footer(function (Form\Footer $footer) {
		    $footer->disableViewCheck();
		    $footer->disableCreatingCheck();
		    $footer->disableEditingCheck();
	    });
    }

	protected function formSaved(Form $form)
	{
		$form->saved(function () {
			admin_toastr('全局配置已更新', 'success');
			return redirect(route('admin.configs.edit', 1));
		});
	}
}
